#include <boost/regex/v4/cregex.hpp>

#include "FileType.h"

std::string FileType::extractFileName(std::string path) {
    std::string aux;
    int index = 0;
    int find = 0;
    VectorString vector = StaticUtils::split(path,"/");
    std::string value = vector.at(vector.size() - 1);
    aux=value;
    if (aux.length() > 0) {
        find = aux.find_last_of(".");
        if (find != -1) {
           aux = aux.substr(0,find);
        } else {
            aux="";
        }
    }
    return aux;
}

void FileType::replace(std::string& string) {
    std::vector<std::string>::iterator ite = replaceWords.begin();
    for(;ite!=replaceWords.end();ite++){
        int index = 0;
        int find = 0;
        while ((unsigned int) find < string.length() && find != -1) {
            if (string.length() > 0) {
                find = string.find_first_of(*ite, index);
                if (find == -1) {
                    break;
                }
                string.replace(find,1,(*ite).length(),' ');
            }
        }
    }
}


void FileType::matchStopWords(std::vector<std::string>& value) {
    std::set<std::string>::iterator ite;
    std::vector<std::string>::iterator iteValue = value.begin();
    for(;iteValue!=value.end();) {
        ite = FileParser::stopWords.find(*iteValue);
        if(ite!=FileParser::stopWords.end()) {
            iteValue=value.erase(iteValue);
        } else {
            iteValue++;
        }
    }
}

void FileType::extractList(EXTRACTOR_KeywordList* list, std::set<std::string>& terminos) {
    list=EXTRACTOR_removeEmptyKeywords (list);
    std::set<int>::iterator ite;
    std::string termino;
    for(;list!=NULL;list=list->next) {
        ite = extractorType.find(list->keywordType);
        if(ite != extractorType.end()) {
            termino=list->keyword;
            StaticUtils::trimo(termino);
            if(!termino.empty() || !StaticUtils::isNumeric(termino))
                terminos.insert(termino);
        }
    }
}

FileType::~FileType() {
    
}
